﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Level9Numbers : MonoBehaviour
{
    public List<TextButton> buttonList;
    public string targetStr = "1297820";
    private string curStr = "";
    private string curDisplayStr = "";

    public Text loveText;
    public Text displayText;
    public GameLevelItem gameLevelItem;
    public uTools.uTweenAlpha tweenAlpha;

    void Start()
    {
        displayText.text = string.Empty;
        BtnEvent();
    }

    private void BtnEvent()
    {
        int count = buttonList.Count;
        for (int i = 0; i < count; i++)
        {
            int tempNumber = i;
            buttonList[i].Init(tempNumber.ToString(), () =>
            {
                if (GameCtrl.Instance.curGameState != GameState.Play) return;
                curStr += tempNumber;
                curDisplayStr += tempNumber + " ";
                displayText.text = curDisplayStr;
                JudgeResult();
            });
        }
    }

    private void JudgeResult()
    {
        if (curStr.Length == targetStr.Length)
        {
            bool result = curStr.Equals(targetStr);
            if (result)
                tweenAlpha.Play(uTools.PlayDirection.Forward);
            gameLevelItem.TriggerResult(result);

        }
    }


}
